/*
 * Saphre - Suffix Arrays for Phrase Extraction
 * Copyright (C) 2013 
 * Dale Gerdemann - Tübingen, Germany 
 * Niko Schenk - Frankfurt am Main, Germany
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package util;

import java.util.*;

/**
 * This class is a wrapper to make a sequence of int look like a string
 * StringBuilder. The purpose is to make it easy to use string
 * algorithms with int[]. I was in a hurry with this one and just did
 * something quick and dirty.
 * 
 * @author Dale Gerdemann
 */
public final class IntStringBuilder
        implements Comparable<IntStringBuilder> {

    private ArrayList<Integer> value;  // characters
    //private static int[] typeSpec = new int[0];

    public IntStringBuilder() {
        value = new ArrayList<Integer>();
    }

    public int charAt(int i) {
        return value.get(i);
    }

    public int length() {
        return value.size();
    }

    public IntStringBuilder append(int c) {
        value.add(c);
        return this;
    }

    public IntStringBuilder append(IntStringBuilder s) {
        value.addAll(s.value);
        return this;
    }

    @Override
    public int compareTo(IntStringBuilder other) {
        return value.toString().compareTo(other.value.toString());
    }

    @Override
    public String toString() {
        return value.toString();
    }

    public IntString toIntString() {
        int[] value1 = new int[value.size()];
        for (int i = 0; i < value.size(); i++) {
            value1[i] = value.get(i);
        }
        return new IntString(value1);
    }
}
